package cw.ulti;

import java.awt.event.*;
import javax.swing.*;

public class Keyboard extends JPanel // MyFrameWithExitHandling
{
    static final String KEYB = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    JButton btList[];
    String keyBuffer = "";
    static String keyPressed="";

    public static String getKeyPressed() {
        return keyPressed;
    }

    public static void setKeyPressed(String keyPressed) {
        Keyboard.keyPressed = keyPressed;
    }

    public void key() {
        int n = KEYB.length();
        btList = new JButton[n];
        for (int i = 0; i < n; i++) {
            btList[i] = new JButton("" + KEYB.charAt(i));
            add(btList[i]);
            btList[i].addMouseListener(new MouseAdapter() {
                @Override
                public void mousePressed(MouseEvent e) {
                    //Display virtual keyboard
                    int n = KEYB.length();
                    // new tests by DreadedTuesday
                    for (int i = 0; i < n; i++) {
                        if (e.getSource() == btList[i]) {
                            keyBuffer += KEYB.charAt(i);
                            keyPressed = String.valueOf(KEYB.charAt(i));
                            System.out.println(KEYB.charAt(i));
                            break;
                        }// end of if
                    }// end of for
                }
            });
        }
    }
    public static void main(String[] args) {
        JDialog frame = new JDialog();
        Keyboard panel=  new Keyboard();
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.setResizable(false);
        frame.setModal(true);
        frame.setTitle("Cross-Words Virtual keyboard");
        panel.key();
        frame.getContentPane().add(panel, "Center");
        frame.pack();
        frame.setSize(300, 140);

        frame.setVisible(true);

    }
}//end class

